<?php

class Api_hoadonController extends Zend_Controller_Action
{

    public function init()
    {
        $option=array(
        		"layout" => "layout",
        		"layoutPath" => APPLICATION_PATH."/layouts/scripts/printing"
        );
        Zend_Layout::startMvc($option);
        
        $this->view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');
    }
   
    public function indexAction()
    {
        $this->_helper->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);
    }
    
    
    public function luuhoadonAction()
    {
        $this->_helper->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);
        
        $idBan = $this->_request->getParam("idBan","-1");
        
        $tongtienthanhtoan = $this->_request->getParam("tienthanhtoan","-1");
        $tienthanhtoan = $this->_request->getParam("tienthanhtoan","-1");
        
        $tienkhachdua = $this->_request->getParam("tienkhachdua","-1");
        $tientralai = $this->_request->getParam("tientralai","-1");
        $ghichu = $this->_request->getParam("ghichu","");
        $giamgia = $this->_request->getParam("giamgia","");
        $lstIdLuutamDachon = $this->_request->getParam("lstIdLuutamDachon","(0)");
        
       	$obHoadon = new Api_Model_Hoadon();
        $obHoadon->IdBan = $idBan;
        $obHoadon->Khachdua = $tienkhachdua;
        $obHoadon->Tongtienthanhtoan = $tongtienthanhtoan;
        $obHoadon->Tienthanhtoan = $tienthanhtoan;
        $obHoadon->Tralai = $tientralai;
        $obHoadon->Thoigianthanhtoan = date('Y-m-d H:i:s');
        $obHoadon->Ghichu = $ghichu;
        $obHoadon->Giamgia = $giamgia;
        
        //$obHoadon->Luuhoadon();
        
         echo json_encode($obHoadon->Luuhoadon($lstIdLuutamDachon));
    }
    
    public function getdshoadontheongayAction()
    {
        $this->_helper->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);
        
        $ngaylaphoadon = $this->_request->getParam("ngaylaphoadon","");
       	$ngay = $pieces = explode("-", $ngaylaphoadon); 
        
        $obHoadon = new Api_Model_Hoadon();
		$tungay = $ngay[2] . '-' . $ngay[1] . '-' .  $ngay[0] . ' 00:00:00';
		$denngay = $ngay[2] . '-' . $ngay[1] . '-' .  $ngay[0] . ' 23:59:59';
        
        echo json_encode($obHoadon->getdshoadontheongay($tungay, $denngay));
    }
    
    public function printingAction()
    {
        $sohoadon = $this->_request->getParam("sohoadon","");
        $obHoadon = new Api_Model_Hoadon();
        
        $rsHoadon = $obHoadon->getdshoadontheoId($sohoadon);
        
        $this->view->obHoadon = $rsHoadon;
        
        //var_dump($rsHoadon[0]);
    }
    
    public function xoahoadonbyidAction()
    {
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->viewRenderer->setNoRender(true);
    
    	$id = $this->_request->getParam("id","-1");
    	$obHoaDon = new Api_Model_Hoadon();
    	$obluutam = new Api_Model_Luutam();
    	$obHoaDon->Sophieu = $id;
    	$obHoaDon->xoaHoadonById();
    	$obluutam->xoaluutamBySohoadon($id);
    }
    
    public function cancelorderAction()
    {
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->viewRenderer->setNoRender(true);
    
    	$idBan = $this->_request->getParam("idBan","-1");
    	$obLuutam = new Api_Model_Luutam();
    	$obLuutam->cancelOder($idBan);
    }
    
}



